package com.vilinno.tlias.service.impl;

import com.vilinno.tlias.mapper.ClazzMapper;
import com.vilinno.tlias.mapper.EmpMapper;
import com.vilinno.tlias.mapper.StudentMapper;
import com.vilinno.tlias.pojo.ClazzCountOption;
import com.vilinno.tlias.pojo.JobOption;
import com.vilinno.tlias.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private ClazzMapper clazzMapper;
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public JobOption getEmpJobData() {

        List<Map<String, Object>> list = empMapper.countEmpJobData();

        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();

        return new JobOption(jobList, dataList);

    }

    @Override
    public List<Map<String, Object>> getEmpGenderData() {

        return  empMapper.countEmpGenderData();

    }

    @Override
    public ClazzCountOption getStudentCountData(){

        List<Map<String, Object>> list = clazzMapper.countStudentCountData();

        List<Object> clazzList = list.stream().map(dataMap -> dataMap.get("clazz")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();

        return new ClazzCountOption(clazzList, dataList);
    }

    @Override
    public List<Map<String, Object>> getStudentDegreeData(){
        return studentMapper.countStudentDegreeData();
    }
}
